package ga.stopcriterias;

import ga.individuals.Individual;

import java.util.Collection;
import java.util.Collections;

public class OptimalStrategy implements StopStrategy {
	double closeness, maximun;
	
	public OptimalStrategy(double closeness, double maximun) {
		this.closeness = closeness;
		this.maximun = maximun;
	}

	@Override
	public boolean execute(Collection<Individual> population) {
		Individual best = Collections.max(population);
		if (Math.abs((best.getFitnessValue() - this.maximun)) <= this.closeness) {
			return true;
		} else {
			return false;
		}
	}
}